﻿@{
    ViewBag.Title = "Регистрация";
    Layout = "~/Views/Shared/_Layout.cshtml";

    var public_key = System.Configuration.ConfigurationManager.AppSettings["CAPTCHA_PUBLIC_KEY"];
    
}

<script>
    $(function () {

        var start_view = Backbone.View.extend({
            el: $("#start-page"),

            render: function () {
                $(".block").hide();
                $(this.el).show();
            },

            events: {
                "click .btn[data-action='saveUser']": "registerUser",
                "click .btn[data-action='back']": "back"
            },

            registerUser: function () {

                var password = $("input[name='PASSWORD']").val();
                var password_check = $("input[name='PASSWORD_CHECK']").val();

                if (password != password_check) {
                    $("#alertMessage").text("Пароль не совпадает");
                    $("#alert").show();
                    return;
                }

                $.ajax({
                    type: 'POST',
                    url: '/security/Register/',
                    data: $("form[name='SEC_USERS']").serialize(),
                    success: function () {
                        window.history.back();
                    },
                    error: function (data) {
                        var error = jQuery.parseJSON(data.responseText);
                        var errorMessage = error.message;

                        $("#alertMessage").text(errorMessage);
                        $("#alert").show();
                    }
                });
            },

            back: function () {
                window.history.back();
            }

        });

        var Controller = Backbone.Router.extend({
            routes: {
                "": "start", // Пустой hash-тэг
                "!/": "start" // Начальная страница
            },

            initialize: function (options) {
            },

            start: function () {
                var view = new start_view();
                view.render();
            }
        });

        var controller = new Controller(); // Создаём контроллер
        Backbone.history.start();  // Запускаем HTML5 History push 

    });
</script>


<header class="jumbotron subhead" id="overview">
    <h1></h1>
    <p class="lead">Регистрация</p>
</header>

<div class="page">

    <div class="block" id="start-page">

        <div class="form-actions">
            <a href="javascript:void(0);" class="btn" data-action="back">
                <i class="icon-circle-arrow-left"></i> Назад</a>
 
            <div class="pull-right">
                <a href="javascript:void(0);" class="btn btn-primary" data-action="saveUser">
                    Зарегистрироватся</a>
            </div>
        </div>

        <div class="alert alert-error hide" id="alert">
            <h4>Ошибка!</h4>
            <span id="alertMessage"></span>
        </div>

        <div>
            <form name="SEC_USERS" class="form-horizontal" method="post"> 
                <fieldset> 

                    <div class="control-group"> 
                        <label class="control-label" for="LASTNAME">Фамилия</label>
                        <div class="controls">
                            <input type="text" class="input-large" name="LASTNAME" value="" />
                        </div> 
                    </div> 

                    <div class="control-group"> 
                        <label class="control-label" for="FIRSTNAME">Имя</label>
                        <div class="controls">
                            <input type="text" class="input-large" name="FIRSTNAME" value="" />
                        </div> 
                    </div> 

                    <div class="control-group"> 
                        <label class="control-label" for="MIDNAME">Отчество</label>
                        <div class="controls">
                            <input type="text" class="input-large" name="MIDNAME" value="" />
                        </div> 
                    </div> 

                    <div class="control-group error"> 
                        <label class="control-label" for="EMAIL">Email</label>
                        <div class="controls">
                            <input type="text" class="input-large" name="EMAIL" value="" />
                        </div> 
                    </div> 

                    <div class="control-group error"> 
                        <label class="control-label" for="PASSWORD">Пароль</label>
                        <div class="controls">
                            <input type="password" class="input-large" name="PASSWORD" value="" />
                        </div> 
                    </div>
                    
                    <div class="control-group error"> 
                        <label class="control-label" for="PASSWORD_CHECK">Повторите пароль</label>
                        <div class="controls">
                            <input type="password" class="input-large" name="PASSWORD_CHECK" value="" />
                        </div> 
                    </div> 

                    <div class="control-group"> 
                        <label class="control-label" for="TIMEZONE">Часовая зона</label>
                        <div class="controls">
                            <select class="input-xlarge" name="TIMEZONE">
                                  <option value="-12">(GMT -12:00) Eniwetok, Kwajalein</option>
                                  <option value="-11">(GMT -11:00) Midway Island, Samoa</option>
                                  <option value="-10">(GMT -10:00) Hawaii</option>
                                  <option value="-9">(GMT -9:00) Alaska</option>
                                  <option value="-8">(GMT -8:00) Pacific Time (US &amp; Canada)</option>
                                  <option value="-7">(GMT -7:00) Mountain Time (US &amp; Canada)</option>
                                  <option value="-6">(GMT -6:00) Central Time (US &amp; Canada), Mexico City</option>
                                  <option value="-5">(GMT -5:00) Eastern Time (US &amp; Canada), Bogota, Lima</option>
                                  <option value="-4">(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz</option>
                                  <option value="-3">(GMT -3:00) Brazil, Buenos Aires, Georgetown</option>
                                  <option value="-2">(GMT -2:00) Mid-Atlantic</option>
                                  <option value="-1">(GMT -1:00 hour) Azores, Cape Verde Islands</option>
                                  <option value="0">(GMT) Western Europe Time, London, Lisbon, Casablanca</option>
                                  <option value="1">(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris</option>
                                  <option value="2">(GMT +2:00) Kaliningrad, South Africa</option>
                                  <option value="3">(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg</option>
                                  <option value="4">(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi</option>
                                  <option value="5">(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
                                  <option value="6">(GMT +6:00) Almaty, Dhaka, Colombo</option>
                                  <option value="7">(GMT +7:00) Bangkok, Hanoi, Jakarta</option>
                                  <option value="8">(GMT +8:00) Beijing, Perth, Singapore, Hong Kong</option>
                                  <option value="9">(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk</option>
                                  <option value="10">(GMT +10:00) Eastern Australia, Guam, Vladivostok</option>
                                  <option value="11">(GMT +11:00) Magadan, Solomon Islands, New Caledonia</option>
                                  <option value="12">(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka</option>
                            </select>
                        </div> 
                    </div> 
                    
                    <div class="control-group error"> 
                        <label class="control-label" for=""></label>
                        <div class="controls">
                            @ReCaptcha.GetHtml(public_key, theme: "white")
                        </div> 
                    </div> 

                </fieldset>
            </form>
        </div>

    </div>
</div>